﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ARS.Control.Common.EntityManage;
using ARS.Control.Custom.Entity.Attributes;
using ARS.Control.Custom.Entity.Common;
using ARS.Control.Custom.Entity.Fields;
using ARS.Control.Factory;
using ARS.PublicTool.DataHandle;

namespace ARS.Control.Custom.Entity.Widget
{

    public abstract class EntityControl : EntityBaseControl
    {

        private Control.Interface.IDialog dialog;
        protected override Control.Interface.IDialog GetDialog()
        {
            if (dialog == null)
            {
                dialog = ARS.Control.Factory.DialogFactory.CreateDialog();
            }
            return dialog;
        }


        protected override EntityTableInfo GetCacheEntityTableInfo()
        {
            string cacheName = "EntityControl" + this.TypeModel.Name;
            EntityTableInfo _EntityTableInfo = (EntityTableInfo)ARS.PublicTool.WebHelper.DataCache.GetCache(cacheName);
            if (_EntityTableInfo == null)
            {
                _EntityTableInfo = new EntityTableInfo(Entity, type);
                ARS.PublicTool.WebHelper.DataCache.SetCache(cacheName, _EntityTableInfo);
            }
            return _EntityTableInfo;
        }



        /// <summary>
        /// 加载主键
        /// </summary>
        protected override void InitKey()
        {
            if (this.IsUseKey)
            {
                string key = HttpContext.Current.Request.QueryString[RequestKey ?? EntityTableInfo.KeyInfo.Key];

                if (key == null)
                {
                    if (EntityTableInfo.KeyInfo.Value > 0)
                    {
                        this.IsAdd = false;
                    }
                }
                else
                {
                    if (this.IsEncryptKey)
                    {
                        key = Encrypt.DecryptString(key);
                    }
                    this.IsAdd = false;
                    EntityTableInfo.KeyInfo.Value = Int32.Parse(key);
                }
            }
            else
            {

            }
        }









    }
}
